package com.nf.health.app.intervention_details.fragment;


import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.google.gson.Gson;
import com.nf.health.app.Constants;
import com.nf.health.app.R;
import com.nf.health.app.fragment.IBaseFragment;
import com.nf.health.app.http.Act;
import com.nf.health.app.intervention_details.adapter.UserHealthInfoAdapter;
import com.nf.health.app.intervention_details.bean.UserHealthInfoBean;
import com.nf.health.app.utils.ViewUtil;

/**
 * 个人健康信息汇总 方案详情
 *
 * @author changpeng 16/11/10
 */
public class UserHealthInfoFragment extends IBaseFragment {

    private RecyclerView mRecyclerView;
    private UserHealthInfoAdapter mUserHealthInfoAdapter;
    private UserHealthInfoBean mUserHealthInfoBean;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        addViewFillInRoot(R.layout.common_layout_recycler);

        mRecyclerView = ViewUtil.getView(rootView, R.id.recycler_view_common);

        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        initData();
    }

    private void initData(){
        provider.getInterveneUserHealthyInfo(Constants.CHANGE_ABLE.INTERVENTION_ID);
    }

    @Override
    public void handleActionSuccess(String actionName, Object object) {
        if(actionName.equals(Act.Flag.GET_INTERVENE_USER_HEALTH_INFO)){
            Gson gson = new Gson();
            mUserHealthInfoBean = gson.fromJson(object+"",UserHealthInfoBean.class);
            if(mUserHealthInfoBean == null){
                return;
            }
            mUserHealthInfoAdapter = new UserHealthInfoAdapter(getActivity(),mUserHealthInfoBean);
            mRecyclerView.setAdapter(mUserHealthInfoAdapter);
        }
    }
}
